DROP TABLE SPP.VARIABLE;

CREATE TABLE SPP.VARIABLE (
       nid_variable         NUMBER(12) NOT NULL,
       txt_descripcion      VARCHAR2(400) NULL,
       txt_fuente           VARCHAR2(400) NULL,
       txt_formula          VARCHAR2(400) NULL,       
       nid_indicador        NUMBER(12) NOT NULL
);


ALTER TABLE SPP.VARIABLE
       ADD  ( PRIMARY KEY (nid_variable) ) ;


ALTER TABLE SPP.VARIABLE
       ADD  ( FOREIGN KEY (nid_indicador)
                             REFERENCES SPP.INDICADOR ) ;

DROP SEQUENCE SPP.SQ_VARIABLE;
CREATE SEQUENCE SPP.SQ_VARIABLE MINVALUE 1 START WITH 1 INCREMENT BY 1 NOCACHE;

CREATE OR REPLACE TRIGGER SPP.VARIABLE_BI
  BEFORE INSERT
  ON SPP.VARIABLE
  FOR EACH ROW
  WHEN (new.NID_VARIABLE is null)
DECLARE
  v_id SPP.VARIABLE.NID_VARIABLE%TYPE;
BEGIN
  SELECT SPP.SQ_VARIABLE.nextval INTO v_id FROM DUAL;
  :new.NID_VARIABLE := v_id;
END VARIABLE_BI;







